<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Table extends CI_Table {
    
    function __construct()
    {
        parent::CI_Table();
        $this->set_template($this->table_tmpl());
    }

    function form_table($form)
    {
        $return = '<table style="width: auto;"><tr><td>';
        $this->set_template($this->form_table_tmpl());
        foreach($form as $k=>$v){
            if(is_numeric($k)){
                $head = array_keys($v);
                $this->set_heading($head);
                $return .= $this->generate($v);
            }else{
                $this->set_heading($k);
                $this->add_row($v);
                $return .= $this->generate();
            }
            
            $this->clear();
        }
        $return .= '</td></tr></table>';
        return $return;
    }
    
    
    function form_table_tmpl()
    {
        return array (
            'table_open'          => '<table class="form" style="width: 100%;">',
            
            'heading_row_start'   => '<tr class="form">',
            'heading_row_end'     => '</tr>',
            'heading_cell_start'  => '<th class="form" style="text-align: left;">',
            'heading_cell_end'    => '</th>',
            
            'row_start'           => '<tr class="form">',
            'row_end'             => '</tr>',
            'cell_start'          => '<td class="form" style="text-align: left;">',
            'cell_end'            => '</td>',
            
            'row_alt_start'       => '<tr class="form">',
            'row_alt_end'         => '</tr>',
            'cell_alt_start'      => '<td class="form" style="text-align: left;">',
            'cell_alt_end'        => '</td>',
            
            'table_close'         => '</table>'
            );
    }
    
    function table_tmpl()
    {
        return array (
            'table_open'          => '<table style="width: auto;" border="1" cellpadding="2" cellspacing="0" id="list">',
            
            'heading_row_start'   => '<tr>',
            'heading_row_end'     => '</tr>',
            'heading_cell_start'  => '<th style="text-align: center;">',
            'heading_cell_end'    => '</th>',
            
            'row_start'           => '<tr class="odd"',
            'row_end'             => '</tr>',
            'cell_start'          => '<td style="text-align: center; background-color: Silver;">',
            'cell_end'            => '</td>',
            
            'row_alt_start'       => '<tr class="even"',
            'row_alt_end'         => '</tr>',
            'cell_alt_start'      => '<td style="text-align: center;">',
            'cell_alt_end'        => '</td>',
            
            'table_close'         => '</table>'
            );
    }
    
}

?>
